package cron;


import cn.hutool.core.thread.ThreadFactoryBuilder;
import main.MyStart;

import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

public class CronJob {
    public static AtomicInteger taskList;

    static ExecutorService executorService ;
    static Timer timer;

    public void strat() {
        taskList = new AtomicInteger(0);
        executorService = new ThreadPoolExecutor(8, 12,
                600L, TimeUnit.SECONDS,
                new LinkedBlockingQueue<Runnable>(1 << 2), new ThreadFactoryBuilder()
                .setNamePrefix("wxpush-batch-pool-").build(), new ThreadPoolExecutor.CallerRunsPolicy());
        timer = new Timer();
        if (MyStart.addr_security != null && MyStart.addr_gamecenter != null) {
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    executorService.execute(() -> {
                        new UpdateGareanPasswordTask().updateGareanPasswordTask();//改密 10个步骤
                    });
                }
            }, 1000, 12000);

            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    executorService.execute(() -> {
                        new CheckAccountTask().checkAccountTask(); //检查账密
                    });
                }
            }, 1000, 60000);
        }
    }
}


